
package net.swa.dewei.web.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Required;

import net.swa.dewei.beans.entity.District;
import net.swa.dewei.beans.entity.PriceChangeLog;
import net.swa.dewei.service.ChangePriceService;
import net.swa.system.beans.entity.Dict;
import net.swa.system.service.ICommonService;
import net.swa.system.util.annotation.Log;
import net.swa.system.web.action.AbstractBaseAction;
import net.swa.util.BuzConst;
import net.swa.util.JsonResult;
import net.swa.util.http.HttpServletUtil;

/**统一修改电池价格，信息 Action**/
public class ChangePriceAction extends AbstractBaseAction
{
    private static final long serialVersionUID = 5260813285345719114L;

    //一次修改对应的实体
    private PriceChangeLog model;

    /** 公用方法接口 */
    private ICommonService commonService;

    /**省列表**/
    private List<District> provinceList;

    /**市列表*/
    private List<District> cityList;

    /**县区列表*/
    private List<District> areaList;

    /**电池类型**/
    private List<Dict> dianchiTypes;

    /**电池品牌**/
    private List<Dict> dianchiPinPais;

    private ChangePriceService changePriceService;

    @Log(description = "进入统一修改电池价格界面")
    public String initAdd()
    {
        dianchiTypes = commonService.search("title", "电池型号", Dict.class, null, "dictPaixu", "asc");
        dianchiPinPais = commonService.search("title", "电池品牌", Dict.class, null, "dictPaixu", "asc");
        provinceList = commonService.search("pid", "0", District.class, null, "sort", "asc");

        model = new PriceChangeLog();
        model.setType(BuzConst.PRICE_CHANGE_TYPE_PLUS);

        return "initAdd";
    }

    @Log(description = "进入统一修改电池价格界面")
    public String doChangePrice() throws Exception
    {
        JsonResult<String> json = new JsonResult<String>();
        if (null != model)
        {
            model.setIp(HttpServletUtil.getIpFromRequest(getRequest()));
            model.setUserid(getCurrentUser().getUserid());
            json = changePriceService.addChangePrice(model);
        }
        else
        {
            json.setSuccess(false);
            json.setMessage("error");
        }
        outJson(json);
        return null;
    }

    @Required
    @Resource
    public void setCommonService(ICommonService commonService)
    {
        this.commonService = commonService;
    }

    public ICommonService getCommonService()
    {
        return commonService;
    }

    public PriceChangeLog getModel()
    {
        return model;
    }

    public void setModel(PriceChangeLog model)
    {
        this.model = model;
    }

    public List<District> getProvinceList()
    {
        return provinceList;
    }

    public void setProvinceList(List<District> provinceList)
    {
        this.provinceList = provinceList;
    }

    public List<District> getCityList()
    {
        return cityList;
    }

    public void setCityList(List<District> cityList)
    {
        this.cityList = cityList;
    }

    public List<District> getAreaList()
    {
        return areaList;
    }

    public void setAreaList(List<District> areaList)
    {
        this.areaList = areaList;
    }

    public List<Dict> getDianchiTypes()
    {
        return dianchiTypes;
    }

    public void setDianchiTypes(List<Dict> dianchiTypes)
    {
        this.dianchiTypes = dianchiTypes;
    }

    public List<Dict> getDianchiPinPais()
    {
        return dianchiPinPais;
    }

    public void setDianchiPinPais(List<Dict> dianchiPinPais)
    {
        this.dianchiPinPais = dianchiPinPais;
    }

    public ChangePriceService getChangePriceService()
    {
        return changePriceService;
    }

    @Required
    @Resource
    public void setChangePriceService(ChangePriceService changePriceService)
    {
        this.changePriceService = changePriceService;
    }

}
